package com.qys.livesMall.app.user.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.app.user.model.dto.sys.LimitUrlSaveDTO;
import com.qys.livesMall.app.user.model.dto.sys.SysLimitUrlPageDTO;
import com.qys.livesMall.app.user.model.vo.sys.LimitUrlVO;
import com.qys.livesMall.app.user.model.vo.sys.LimitVO;
import com.qys.livesMall.app.user.service.LimitService;
import com.qys.livesMall.app.user.service.LimitUrlService;
import com.qys.livesMall.app.user.service.SysInviteRewardsService;
import com.qys.livesMall.common.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户权限控制 前端控制器
 * </p>
 *
 * @author
 * @since 2023-07-31
 */
@RestController
@Tag(name = "sys-app用户权限控制")
@RequestMapping("/sys/app/user/limit")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysLimitController {


    private final LimitService limitService;
    private final LimitUrlService limitUrlService;

    @PostMapping("/limitList")
    @Operation(summary = "权限控制列表")
    public R<List<LimitVO>> userLimit(@RequestBody SysLimitUrlPageDTO queryDTO) {
        if (queryDTO.getUserId()==null){
            return R.fail("请一定传用户ID");
        }
        List<LimitVO> limitVOList = limitService.userLimit(queryDTO);
        return R.ok(limitVOList);
    }

    @PutMapping(value = "/coLimit/{id}")
    @Operation(
            summary = "关闭/打开权限",
            parameters = {
                    @Parameter(name = "id", description = "用户权限控制ID")
            }
    )
    public R<Void> coLimit(@PathVariable String id) {
        limitService.coLimit(id);
        return R.ok();
    }

    @PostMapping("/list")
    @Operation(summary = "分页查询接口权限列表")
    public R<Page<LimitUrlVO>> list(@RequestBody SysLimitUrlPageDTO queryDTO) {
        return R.ok(limitUrlService.pageBySys(queryDTO));
    }

    @PostMapping("/addOrUpdate")
    @Operation(summary = "新增接口权限验证")
    public R<Void> addOrUpdate(@RequestBody @Validated LimitUrlSaveDTO saveDTO) {
        limitUrlService.saveOrUpdate(saveDTO);
        return R.ok();
    }


    @Operation(
            summary = "删除接口权限验证",
            parameters = {
                    @Parameter(name = "id", description = "接口权限id")
            }
    )
    @DeleteMapping(value = "/delete/{id}")
    public R<Void> deleteById(@PathVariable Long id) {
        limitUrlService.deleteById(id);
        return R.ok();
    }


    @PutMapping("/shelves/{id}")
    @Operation(
            summary = "打开关闭",
            parameters = {
                    @Parameter(name = "id", description = "接口权限id")
            }
    )
    public R<Void> shelves(@PathVariable("id") Long id) {
        limitUrlService.shelves(id);
        return R.ok();
    }


    @GetMapping("/{id}")
    @Operation(summary = "根据id查询直播礼物信息", parameters = {@Parameter(name = "id", description = "直播礼物id")})
    public R<LimitUrlVO> queryById(@PathVariable Long id) {
        return R.ok(limitUrlService.queryById(id));
    }


}
